package com.lb.controller;

import com.lb.entity.TbMovie;
import com.lb.service.TbMovieService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (TbMovie)表控制层
 *
 * @author libo
 * @since 2024-09-09 14:09:14
 */
@RestController
@RequestMapping("tbMovie")
public class TbMovieController {
    /**
     * 服务对象
     */
    @Resource
    private TbMovieService tbMovieService;

    /**
     * 分页查询
     *
     * @param tbMovie     筛选条件
     * @param pageRequest 分页对象
     * @return 查询结果
     */
    @GetMapping
    public ResponseEntity<Page<TbMovie>> queryByPage(TbMovie tbMovie, PageRequest pageRequest) {
        return ResponseEntity.ok(this.tbMovieService.queryByPage(tbMovie, pageRequest));
    }
    @GetMapping("/getList")
    public ResponseEntity<List<TbMovie>> queryAll() {
        return this.tbMovieService.queryAll();
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/getById")
    public ResponseEntity<TbMovie> queryById(@RequestParam("id") Integer id) {
        return ResponseEntity.ok(this.tbMovieService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param tbMovie 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<TbMovie> add(TbMovie tbMovie) {
        return ResponseEntity.ok(this.tbMovieService.insert(tbMovie));
    }

    /**
     * 编辑数据
     *
     * @param tbMovie 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<TbMovie> edit(TbMovie tbMovie) {
        return ResponseEntity.ok(this.tbMovieService.update(tbMovie));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Integer id) {
        return ResponseEntity.ok(this.tbMovieService.deleteById(id));
    }

}

